package com.ruoyi.common.utils.android;

import java.util.Arrays;

/* loaded from: classes.dex */
public abstract class b implements d, c {
    protected final byte a;
    private final int b;

    /* renamed from: decrypt.c */
    private final int f950c;

    /* renamed from: decrypt.d */
    protected final int f951d;

    /* renamed from: decrypt.e */
    private final int f952e;

    /* loaded from: classes.dex */
    public static class a {
        int a;
        long b;

        /* renamed from: decrypt.c */
        byte[] f953c;

        /* renamed from: decrypt.d */
        int f954d;

        /* renamed from: decrypt.e */
        int f955e;
        boolean f;
        int g;
        int h;

        a() {
        }

        public String toString() {
            return String.format("%s[buffer=%s, currentLinePos=%s, eof=%s, ibitWorkArea=%s, lbitWorkArea=%s, modulus=%s, pos=%s, readPos=%s]", a.class.getSimpleName(), Arrays.toString(this.f953c), Integer.valueOf(this.g), Boolean.valueOf(this.f), Integer.valueOf(this.a), Long.valueOf(this.b), Integer.valueOf(this.h), Integer.valueOf(this.f954d), Integer.valueOf(this.f955e));
        }
    }

    public b(int i, int i2, int i3, int i4) {
        this(i, i2, i3, i4, (byte) 61);
    }

    public static boolean b(byte b) {
        return b == 9 || b == 10 || b == 13 || b == 32;
    }

    private byte[] b(a aVar) {
        byte[] bArr = aVar.f953c;
        if (bArr == null) {
            aVar.f953c = new byte[a()];
            aVar.f954d = 0;
            aVar.f955e = 0;
        } else {
            byte[] bArr2 = new byte[bArr.length * 2];
            System.arraycopy(bArr, 0, bArr2, 0, bArr.length);
            aVar.f953c = bArr2;
        }
        return aVar.f953c;
    }

    protected int a() {
        return 8192;
    }

    int a(a aVar) {
        if (aVar.f953c != null) {
            return aVar.f954d - aVar.f955e;
        }
        return 0;
    }

    abstract void a(byte[] bArr, int i, int i2, a aVar);

    protected abstract boolean a(byte b);

    abstract void b(byte[] bArr, int i, int i2, a aVar);

    int c(byte[] bArr, int i, int i2, a aVar) {
        if (aVar.f953c == null) {
            return aVar.f ? -1 : 0;
        }
        int min = Math.min(a(aVar), i2);
        System.arraycopy(aVar.f953c, aVar.f955e, bArr, i, min);
        aVar.f955e += min;
        if (aVar.f955e >= aVar.f954d) {
            aVar.f953c = null;
        }
        return min;
    }

    @Override // com.md.obj.binary.decrypt.g
    public Object decode(Object obj) throws DecoderException {
        if (obj instanceof byte[]) {
            return decode((byte[]) obj);
        }
        if (obj instanceof String) {
            return decode((String) obj);
        }
        throw new DecoderException("Parameter supplied to Base-N decode is not decrypt.a byte[] or decrypt.a String");
    }

    @Override // com.md.obj.binary.decrypt.h
    public Object encode(Object obj) throws EncoderException {
        if (obj instanceof byte[]) {
            return encode((byte[]) obj);
        }
        throw new EncoderException("Parameter supplied to Base-N encode is not decrypt.a byte[]");
    }

    public String encodeAsString(byte[] bArr) {
        return II.newStringUtf8(encode(bArr));
    }

    public String encodeToString(byte[] bArr) {
        return II.newStringUtf8(encode(bArr));
    }

    public long getEncodedLength(byte[] bArr) {
        int length = bArr.length;
        int i = this.b;
        long j = (((length + i) - 1) / i) * this.f950c;
        int i2 = this.f951d;
        return i2 > 0 ? j + ((((i2 + j) - 1) / i2) * this.f952e) : j;
    }

    public boolean isInAlphabet(byte[] bArr, boolean z) {
        for (int i = 0; i < bArr.length; i++) {
            if (!a(bArr[i]) && (!z || (bArr[i] != this.a && !b(bArr[i])))) {
                return false;
            }
        }
        return true;
    }

    protected b(int i, int i2, int i3, int i4, byte b) {
        this.b = i;
        this.f950c = i2;
        this.f951d = i3 > 0 && i4 > 0 ? (i3 / i2) * i2 : 0;
        this.f952e = i4;
        this.a = b;
    }

    public byte[] a(int i, a aVar) {
        byte[] bArr = aVar.f953c;
        return (bArr == null || bArr.length < aVar.f954d + i) ? b(aVar) : bArr;
    }

    public boolean a(byte[] bArr) {
        if (bArr == null) {
            return false;
        }
        for (byte b : bArr) {
            if (this.a == b || a(b)) {
                return true;
            }
        }
        return false;
    }

    @Override // com.md.obj.binary.decrypt.d
    public byte[] encode(byte[] bArr) {
        if (bArr == null || bArr.length == 0) {
            return bArr;
        }
        a aVar = new a();
        b(bArr, 0, bArr.length, aVar);
        b(bArr, 0, -1, aVar);
        byte[] bArr2 = new byte[aVar.f954d - aVar.f955e];
        c(bArr2, 0, bArr2.length, aVar);
        return bArr2;
    }

    public boolean isInAlphabet(String str) {
        return isInAlphabet(II.getBytesUtf8(str), true);
    }

    public byte[] decode(String str) {
        return decode(II.getBytesUtf8(str));
    }

    @Override // com.md.obj.binary.decrypt.c
    public byte[] decode(byte[] bArr) {

        System.out.println("decrypt.b bArr.size = " + bArr.length);

        if (bArr == null || bArr.length == 0) {
            return bArr;
        }
        a aVar = new a();
        a(bArr, 0, bArr.length, aVar);
        a(bArr, 0, -1, aVar);
        byte[] bArr2 = new byte[aVar.f954d];
        c(bArr2, 0, bArr2.length, aVar);

        System.out.println("decrypt.b bArr2.size = " + bArr2.length);

        return bArr2;
    }
}
